<?xml version="1.0" encoding="UTF-8"?>
<ui:composition template="/WEB-INF/templates/portalTemplate.xhtml"
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:a4j="http://richfaces.org/a4j"
	xmlns:rich="http://richfaces.org/rich"
	xmlns:p="http://primefaces.org/ui"
	xmlns:my="http://java.sun.com/jsf/composite/components">
	<ui:define name="content">
		<h:form>
			<p:growl id="growl" showDetail="true" sticky="false"  />  
			<rich:panel header="Witaj w lekcji nr #{lessonBean.lesson.number}">
				<p:messages id="messagesTop" showDetail="true" autoUpdate="true" />
				<div class="introductionDiv">
					<h:outputText value="Cel: " styleClass="blueHeader"/>
					<h:outputText value="#{lessonBean.lesson.introduction}" />
				</div>

				<br />

				<rich:dataGrid value="#{lessonBean.questionAnswerList}" var="_qa" rowClasses="test"
					columns="1" id="grid" style="width:100%;" 
					elements="#{lessonBean.questionAnswerList.size()}">

					<h:panelGrid columns="1" width="100%">
						<h:outputText value="Pytanie #{_qa.question.number}" styleClass="blueHeader"/>
						<h:outputText escape="false"
							value="#{_qa.question.content}"  style="width:100%;"/>

						<rich:dataGrid value="#{_qa.question.questionAdditions}" var="_a"
							columns="1" style="width:100%; ">

							<h:graphicImage value="/imageServlet?id=#{_a.id}"
								height="#{_a.height}"
								style="display: block; margin-left: auto; margin-right: auto;float:none;" />

							<div align="center">
								<h:outputText value="#{_a.description}" />
							</div>
							<br />
						</rich:dataGrid>



						<h:inputTextarea id="answer" rows="6" value="#{_qa.answer.content}"
							readonly="#{lessonBean.educationState.sent}"  style="width:100%;"/>
						<p:message for="answer"/>


						<a4j:commandButton value="Zapisz odpowiedź"
							action="#{lessonBean.save()}"
							disabled="#{lessonBean.educationState.sent}" render="@form"
							rendered="#{permissionManagement.studentLogged and lessonBean.isStudent}"
							style="float:right;" styleClass="buttonSmall">
							<rich:tooltip
								value="Zapisz wprowadzoną odpowiedź. Po zapisie będzie możliwość zmiany odpowiedzi." />
						</a4j:commandButton>


					</h:panelGrid>

				</rich:dataGrid>

				<h:outputText styleClass="blueHeader"
						rendered="#{lessonBean.lesson.homework!=null and lessonBean.lesson.homework!='' }"
						value="Praca domowa" />
				<br />
				<h:outputText styleClass="introductionDiv"
						rendered="#{lessonBean.lesson.homework!=null and lessonBean.lesson.homework!='' }"
						value="#{lessonBean.lesson.homework}" escape="false"/>
				<br/>
				<br/>
				<br/>

				<h:outputText styleClass="blueHeader"
					rendered="#{(lessonBean.educationState.sent and lessonBean.isTeacher) or lessonBean.educationState.checked }"
					value="Komentarz nauczyciela" />
				<br />

				<h:inputTextarea rows="6"  style="width:100%;"
					value="#{lessonBean.educationState.comment}"
					rendered="#{(lessonBean.educationState.sent and lessonBean.isTeacher) or lessonBean.educationState.checked }"
					readonly="#{lessonBean.educationState.checked || !permissionManagement.teacherLogged}" />

				<br />
				<p:messages id="messages" showDetail="true" autoUpdate="true" />

				<h:panelGrid columns="2" style="margin-left:auto;">
					<a4j:commandButton value="Zapisz" action="#{lessonBean.save()}"
						disabled="#{lessonBean.educationState.sent}" render="@form"
						rendered="#{permissionManagement.studentLogged and lessonBean.isStudent}">
						<rich:tooltip value="Zapisz bez wysłania rozwiązania" />
					</a4j:commandButton>
					<a4j:commandButton value="Wyślij rozwiązanie"
						action="#{lessonBean.send()}"
						disabled="#{lessonBean.educationState.sent}" render="@form"
						rendered="#{permissionManagement.studentLogged and lessonBean.isStudent}">
						<rich:tooltip value="Zapisz i wyślij rozwiązanie do sprawdzenia" />
					</a4j:commandButton>

					<a4j:commandButton value="Zapisz lekcję jako sprawdzoną"
						action="#{lessonBean.check()}"
						disabled="#{lessonBean.educationState.checked or not lessonBean.educationState.sent}"
						render="@form"
						rendered="#{permissionManagement.teacherLogged and lessonBean.isTeacher}">
						<rich:tooltip value="Oznacz lekcję jako sprawdzoną." />
					</a4j:commandButton>

				</h:panelGrid>



			</rich:panel>
		</h:form>
	</ui:define>
</ui:composition>